package wap._2015.travel;

import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int m = in.nextInt();
		int[] head = new int[n + 1];
		int[] next = new int[n * 2 + 1];
		int[] edge = new int[n * 2 + 1];
		for (int i = 0; i < n - 1; i++) {
			int x = in.nextInt();
			int y = in.nextInt();
			// x -> y
			edge[i * 2 + 1] = y;
			next[i * 2 + 1] = head[x];
			head[x] = i * 2 + 1;
			// y -> x
			edge[i * 2 + 2] = x;
			next[i * 2 + 2] = head[y];
			head[y] = i * 2 + 2;
		}
		
		int[] distance = new int[n + 1];
		boolean[] inQueue = new boolean[n + 1];
		Queue<Integer> queue = new LinkedList<Integer>();
		for (int i = 2; i <= n; i++) {
			distance[i] = n + 1;
			inQueue[i] = false;
		}
		distance[1] = 0;
		inQueue[1] = true;
		queue.add(1);
		for (int i = 0; i < m; i++) {
			int op = in.nextInt();
			int p = in.nextInt();
			if (op == 1) {
				distance[p] = 0;
				if (!inQueue[p]) {
					inQueue[p] = true;
					queue.add(p);
				}
			} else {
				while (!queue.isEmpty()) {
					int now = queue.poll();
					inQueue[now] = false;
					
					// visit its neighbors
					int point = head[now];
					while (point > 0) {
						int y = edge[point];
						if (distance[now] + 1 < distance[y]) {
							distance[y] = distance[now] + 1;
							if (!inQueue[y]) {
								inQueue[y] = true;
								queue.add(y);
							}
						}
						point = next[point];
					}
				}
				System.out.println(distance[p]);
			}
		}
		in.close();
	}
}
